﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace MvcApplication1.Models
{
    public class RepositorioForo : RepositorioBase, MvcApplication1.Models.IRepositorioForo
    {
        public IQueryable<Topic> TodosLosTopics()
        {
            return db.Topics;
        }

        public IQueryable<Comentario> TodosLosComentarios()
        {
            return db.Comentarios;
        }

        public Topic getTopic(int indice)
        {
            return db.Topics.SingleOrDefault(d => d.IDTopic == indice);
        }

        public Comentario getComentario(int indice)
        {
            return db.Comentarios.SingleOrDefault(d => d.IDComentario == indice);
        }

        public void AgregarTopic(Topic t)
        {
            db.Topics.InsertOnSubmit(t);
        }

        public void AgregarComentario(Comentario c)
        {
            db.Comentarios.InsertOnSubmit(c);
        }

        public void EliminarTopic(Topic t)
        {
            foreach (Comentario c in t.Comentarios)
            {
                this.EliminarComentario(c);
            }
            db.Topics.DeleteOnSubmit(t);
        }

        public void EliminarComentario(Comentario c)
        {
            db.Comentarios.DeleteOnSubmit(c);
        }
    }
}